<% layout('boilerplate') -%>
<link rel="stylesheet" href="<%= linkPath %>/css/style.css">
<script type="text/javascript" src="<%= linkPath %>/lib/nativeSchema.js"></script>
<script type="text/javascript" src="<%= linkPath %>/js/index.js"></script>
<script src="//cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>
<style>
    .mainContent {
        width: 100%;
        height: 100%;
        background-size: cover;
        background-repeat: no-repeat;
    }
    .btnCont {
        position: fixed;
        width: 100%;
        bottom: 8%;
        text-align: center;
    }

    .fuceng {
        position: fixed;
        z-index: 1000;
        background: rgba(0,0,0,0.7);
        width: 100%;
        height: 100%;
    }

    .fuceng img {
        width: 200px;
        float: right;
        margin-right: 25px;
    }
</style>
<div class="app-wrapper" style="height: 100%;background: #ff6593;">
    <div class="fuceng hide">
        <img src="<%= linkPath %>/images/share/fuceng.png" alt="share">
    </div>
    <div class="mainContent" style="background-image: url('<%= linkPath %>/images/share/share_bg1.jpg')">

    </div>
    <div class="btnCont" style="">
        <img id="openNN" src="<%= linkPath %>/images/share/downloadBtn.png" alt="">
    </div>
    <!--<div class="nickname"></div>-->
    <!--<div class="imgBox"><img src="" alt=""></div>-->
    <!--<input id="openNN" type="button" value="进入下载页面">-->
</div>
<script>
    $(function () {
        var getQueryString = function () {
            var qs = location.search.substr(1), // 获取url中"?"符后的字串
                args = {}, // 保存参数数据的对象
                items = qs.length ? qs.split("&") : [], // 取得每一个参数项,
                item = null,
                len = items.length;

            if(qs == ''){
                return
            }
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                var name = decodeURIComponent(item[0]),
                    value = decodeURIComponent(item[1]);
                if (name) {
                    args[name] = value;
                }
            }
            return args;
        }
        var query = getQueryString();

        if(!!query){
            var code = query['code'];
            var stateAid = query['state'];   // 类似于 '123_wx'  _ 后是来源
            var source = stateAid.split('_')[1];
            var getUserInfo = function (code) {
                return new Promise(function (resolve,reject) {
                    $.getJSON('/share/work/'+ source +'?code='+code,function (info) {
                        var data = info.data;
                        if(info.code == 1){
                            // $(".nickname").text(data.nickname);
                            // $('.imgBox img').attr('src',data.head_img);
                            data['user_id'] = stateAid.split('_')[0];
                            resolve(data)
                        }else {
                            reject(data.msg);
                        }
                    })
                })
            }
            getUserInfo(code).then(function (data) {
                data['source'] = source;
                $.post('http://tl.yoya.cn/index.php/v1/api/share',data,function (info) {
                    if(info.code == 10000){
                        console.log(info.message);
                    }
                },'json')
            }).catch(function (err) {
                alert(err)
            })
        }


        function isIphoneX(){
            return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375)
        }

        if(isIphoneX()){
            $(".mainContent").css('backgroundSize','contain');
            $('.btnCont').css('bottom','10%')
        }

        if($(window).width() > 767){
            $('.btnCont').css('bottom','3%')
        }

        $('.fuceng').on("click", function () {
            $(this).addClass("hide");
        })

        $("#openNN").on("click",function () {
            var login = "login";
            nativeSchema.loadSchema({
                // 通过NN打开某个链接
                schema: login,
                //schema头协议，实际情况填写
                protocal:"com.zhumey.shop",
                //发起唤醒请求后，会等待loadWaiting时间，超时则跳转到failUrl，默认3000ms
                loadWaiting:"2000",
                //唤起失败时的跳转链接，默认跳转到下载页
                failUrl:{
                  android:'/share/beta.apk',
                  ios:'/share/download?s=ios'
                },
                isQQWX_Callback:function () {
                  $('.fuceng').removeClass('hide');
                },
                // apk信息,请根据实际情况填写
                apkInfo:{
                    PKG: "com.zhumey.android.shop",
                    CATEGORY: "android.intent.category.LAUNCHER",
                    ACTION: "android.intent.action.MAIN"
                }
            });
        })

    })
</script>
